package org.demo.quartz.job;

import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class JobController {

    @Autowired
    private Scheduler scheduler;

    @RequestMapping("/quartz/addJob")
    public String test(String name) throws SchedulerException {
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).storeDurably(true).setJobData(new JobDataMap())
                .withIdentity(name).build();
        Trigger trigger = TriggerBuilder.newTrigger().forJob(jobDetail).withIdentity("trigger_"+name)
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0/15 * * * ?")).build();
        scheduler.scheduleJob(jobDetail, trigger);
        return "添加任务：" + name;
    }
}
